package com.hongxun.project.assets.exportdetailed;

import com.github.pagehelper.PageInfo;
import com.hongxun.framework.config.RuoYiConfig;
import com.hongxun.framework.web.controller.BaseController;
import com.hongxun.framework.web.page.TableDataInfo;
import com.hongxun.project.assets.b10kvLineInfo.service.IB10kvLineInfoService;
import com.hongxun.project.assets.bByq.domain.*;
import com.hongxun.project.assets.bByq.service.IBByqService;
import com.hongxun.project.assets.bDivice.service.IBDiviceService;
import com.hongxun.project.assets.bMaterial.service.IBMaterialService;
import com.hongxun.project.assets.iBoxes.domain.IBoxes;
import com.hongxun.project.assets.iBoxes.service.IIBoxesService;
import com.hongxun.project.assets.iDevice.domain.IDevice;
import com.hongxun.project.assets.iDevice.service.IIDeviceService;
import com.hongxun.project.assets.iLine.domain.ILine;
import com.hongxun.project.assets.iLine.service.IILineService;
import com.hongxun.project.assets.iMaterial.domain.IMaterial;
import com.hongxun.project.assets.iMaterial.service.IIMaterialService;
import com.hongxun.project.assets.iPicture.service.IIPictureService;
import com.hongxun.project.assets.iPoint.domain.IPoint;
import com.hongxun.project.assets.iPoint.service.IIPointService;
import com.hongxun.project.assets.iPole.domain.IPole;
import com.hongxun.project.assets.iPole.service.IIPoleService;
import com.hongxun.project.assets.kBj.domain.KBj;
import com.hongxun.project.assets.kBj.service.IKBjService;
import com.hongxun.project.assets.kCj.domain.KCj;
import com.hongxun.project.assets.kCj.service.IKCjService;
import com.hongxun.project.assets.kHgq.domain.KHgq;
import com.hongxun.project.assets.kHgq.service.IKHgqService;
import com.hongxun.project.assets.kPdKg.domain.KPdKg;
import com.hongxun.project.assets.kPdKg.service.IKPdKgService;
import com.hongxun.project.assets.pDevice.service.IPDeviceService;
import com.hongxun.project.assets.pMaterial.service.IPMaterialService;
import com.hongxun.project.assets.pPicture.service.IPPictureService;
import com.hongxun.project.assets.pPoint.service.IPPointService;
import com.hongxun.project.common.CommonController;
import com.hongxun.project.system.dept.domain.Dept;
import com.hongxun.project.system.dept.service.IDeptService;
import com.hongxun.project.system.user.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import static com.hongxun.common.utils.Arith.div;

/**
 * Created by xhj on 2019/7/15.
 */
@Controller
@RequestMapping("/assets/ThyDetiail")
public class ThyDetiail extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(CommonController.class);
    private String prefix = "assets/bByq/thy";
    private String ROOT = RuoYiConfig.getProfile();



    @Autowired
    private IILineService iLineService;
    @Autowired
    private IBByqService bByqService;
    @Autowired
    private IB10kvLineInfoService b10kvLineInfoService;
    @Autowired
    private IUserService userService;
    @Autowired
    private IPPointService pPointService;
    @Autowired
    private IIPointService iPointService;
    @Autowired
    private IPMaterialService pMaterialService;
    @Autowired
    private IPDeviceService pDeviceService;
    @Autowired
    private IPPictureService pPictureService;
    @Autowired
    private IIPictureService iPictureService;
    @Autowired
    private IBDiviceService bDiviceService;
    @Autowired
    private IBMaterialService bMaterialService;
    @Autowired
    private IIMaterialService iMaterialService;
    @Autowired
    private IIDeviceService iDeviceService;
    @Autowired
    private IIBoxesService iBoxesService;
    @Autowired
    private IDeptService deptService;
    @Autowired
    private IIPoleService iPoleService;
    @Autowired
    private IKBjService kBjService;
    @Autowired
    private IKHgqService kHgqService;
    @Autowired
    private IKCjService kCjService;
    @Autowired
    private IKPdKgService kPdKgService;






    /**
     *  台账table跳转
     */
    @GetMapping("/showThy/{id}")
    public String showThy(@PathVariable("id") String id , ModelMap modelMap)
    {
        modelMap.put("byqId",id);					// 点位ID

        return prefix + "/TZDetailed";
    }

    /**
     *  资产table跳转
     */
    @GetMapping("/showThp/{id}")
    public String showThp(@PathVariable("id") String id , ModelMap modelMap)
    {
        modelMap.put("byqId",id);					// 点位ID

        return prefix + "/ZCDetailed";
    }

    /**
     *  资产
     */
    @GetMapping("/showZC/{id}")
    public String showZC(@PathVariable("id") String id , ModelMap modelMap)
    {
        BByq bByq = bByqService.selectBByqById(id);
        modelMap.put("byqId",id);					// 变压器ID
        modelMap.put("byqName",bByq.getName());
        return prefix + "/ZCXQ";
    }

    /**
     *  台账
     */
    @GetMapping("/showTZ/{id}")
    public String showTZ(@PathVariable("id") String id , ModelMap modelMap)
    {
        BByq bByq = bByqService.selectBByqById(id);
        modelMap.put("byqId",id);					// 变压器ID
        modelMap.put("byqName",bByq.getName());
        return prefix + "/TZXQ";
    }

    /**
     *  杆位table跳转
     */
    @GetMapping("/showGT/{id}")
    public String showGT(@PathVariable("id") String id , ModelMap modelMap)
    {
        modelMap.put("byqId",id);					// 点位ID

        return prefix + "/GTXQ";
    }

    /**
     *  表箱table跳转
     */
    @GetMapping("/showBX/{id}")
    public String showBX(@PathVariable("id") String id , ModelMap modelMap)
    {
        modelMap.put("byqId",id);					// 点位ID

        return prefix + "/BXXQ";
    }

    /**
     *  表计table跳转
     */
    @GetMapping("/showBJ/{id}")
    public String showBJ(@PathVariable("id") String id , ModelMap modelMap)
    {
        modelMap.put("byqId",id);					// 点位ID

        return prefix + "/BJXQ";
    }


    /**
     *  台账详情table
     */
    @PostMapping("/listTZ")
    @ResponseBody
    public TableDataInfo listTZ(TZ tz)
    {

//        startPage();
        List<TZ> tzs = new ArrayList<>();

        BByq bByq = new BByq();
        bByq.setId(tz.getByqId());
        List<BByq> bByqList = bByqService.selectBByqList(bByq);
        //  变压器
        for (BByq byq : bByqList) {
            TZ tzNew = new TZ();
            tzNew.setDeviceName(byq.getName());
            tzNew.setNewRu("台");
            tzNew.setNum("1");
            tzNew.setModel(byq.getModel());
            tzs.add(tzNew);
        }

        IDevice iDevice = new IDevice();
        iDevice.setByqId(tz.getByqId());
        List<IDevice> iDeviceList = iDeviceService.selectIDeviceList(iDevice);
        List<IDevice> list = new ArrayList<>();
        if(iDeviceList != null){
            for (IDevice device : iDeviceList) {
                if (device.getBigType().equals("低压配电柜/盘")
                        || device.getMidType().equals("集中器")
                        || device.getBigType().equals("低压电流互感器")
                        || device.getBigType().equals("分支箱")){
                    list.add(device);
                }
            }
        }
        //  采集器--型号
        KCj kCj = new KCj();
        List<KCj> kCjList = new ArrayList<>();
        for (IDevice device : list) {
            if (device.getMidType().equals("集中器")) {
                kCj.setByqId(device.getByqId());
                kCj.setDeviceId(device.getId());
                kCjList = kCjService.selectKCjList(kCj);
            }
        }


        //  低压电流互感器--型号
        KHgq kHgq = new KHgq();
        List<KHgq> kHgqList = new ArrayList<>();
        for (IDevice device : list) {
            if (device.getBigType().equals("低压电流互感器")) {
                kHgq.setByqId(device.getByqId());
                kHgq.setDeviceId(device.getId());
                kHgqList = kHgqService.selectKHgqList(kHgq);
            }
        }

        //  低压配电柜--型号
        KPdKg kPdKg = new KPdKg();
        kPdKg.setByqId(tz.getByqId());
        List<KPdKg> kPdKgList = new ArrayList<>();
        StringBuffer stringBuffer = new StringBuffer();
        kPdKgList = kPdKgService.selectKPdKgList(kPdKg);
        String opq = "";
        if(kPdKgList.size()!=0){
            for (KPdKg pdKg : kPdKgList) {
                stringBuffer.append(pdKg.getCode());
                stringBuffer.append(";");
            }
            opq = stringBuffer.substring(0,stringBuffer.lastIndexOf(";"));
        }
        for (IDevice device : list) {
            TZ tzNew = new TZ();

            tzNew.setDeviceName(device.getBigType());
            tzNew.setNewRu("台");
            tzNew.setNum("1");
            if(device.getName()!=null) tzNew.setModel(device.getName());

            if(device.getBigType().equals("低压电流互感器")){
                String ac = kHgqList.get(0).getACode();
                String bc = kHgqList.get(0).getBCode();
                String cc = kHgqList.get(0).getCCode();
                tzNew.setCcCode(ac+","+bc+","+cc);
            }else if (device.getMidType().equals("集中器")){
                String code = kCjList.get(0).getCode();
                tzNew.setCcCode(code);
            }else if (device.getBigType().equals("低压配电柜/盘")){
                tzNew.setCcCode(opq);
            }
            tzs.add(tzNew);
        }

        //  关口表
        KBj kBj = new KBj();
        kBj.setByqId(tz.getByqId());
        List<KBj> kBjList = kBjService.selectKBjList(kBj);
        List<KBj> kBjList11 = new ArrayList<>();
        List<IDevice> iDeviceList1 = new ArrayList<>();

        for (KBj bj : kBjList) {
            if (bj.getType() != null && bj.getType().equals("关口表")){
                kBjList11.add(bj);
            }
        }
        for (KBj bj : kBjList11) {
            TZ tzNew = new TZ();
            IDevice iDevice1 = iDeviceService.selectIDeviceById(bj.getBoxId());
            tzNew.setDeviceName("关口表");
            tzNew.setNewRu("只");
            tzNew.setNum("1");
            tzNew.setModel(iDevice1.getName());
            if(bj.getBCode()!= null) tzNew.setCcCode(bj.getBCode());
            tzs.add(tzNew);
        }
        //  三相表箱、表计，单相表箱、表计
        Integer iop = iBoxesService.getCountsForType(tz.getByqId(),"单相" , null);
        String ios = iBoxesService.getCountsListForNum(tz.getByqId(),"单相");
        Integer ioa = iBoxesService.getCountsForType(tz.getByqId(),"三相",null);
        String iod = iBoxesService.getCountsListForNum(tz.getByqId(),"三相");
        for (int i = 0; i < 4; i++) {
            TZ tzNew = new TZ();
            if(i==0){
                tzNew.setDeviceName("单相表箱");
                tzNew.setNewRu("只");
                if(iop != null)tzNew.setNum(iop.toString());else tzNew.setNum("0");
            }else if(i==1){
                tzNew.setDeviceName("单相表计");
                tzNew.setNewRu("只");
                if(ios != null)tzNew.setNum(ios.toString());else tzNew.setNum("0");
            }else if(i==2){
                tzNew.setDeviceName("三相表箱");
                tzNew.setNewRu("只");
                if(ioa != null)tzNew.setNum(ioa.toString());else tzNew.setNum("0");
            }else if(i==3){
                tzNew.setDeviceName("三相表计");
                tzNew.setNewRu("只");
                if(iod != null)tzNew.setNum(iod.toString());else tzNew.setNum("0");
            }
            tzs.add(tzNew);
        }
        //  电杆
        IPoint iPoint11 = new IPoint();
        iPoint11.setByqId(tz.getByqId());
        iPoint11.setType("杆塔");
        List<IPoint> iPointList11 = iPointService.selectIPointList(iPoint11);
        for (int i = 0; i < 1; i++) {
            TZ tzNew = new TZ();
            tzNew.setDeviceName("电杆");
            tzNew.setNewRu("根");
            tzNew.setNum(String.valueOf(iPointList11.size()));
            tzs.add(tzNew);
        }

        /*// 400v线路长度
        Float il400v = iPointService.totalLine(tz.getByqId(),"400v");
        // 220v线路长度
        Float il220v = iPointService.totalLine(tz.getByqId(),"220v");

        if(il400v == null)il400v = 0F ;
        if(il220v == null)il220v = 0F ;*/


        IPoint iPoint_220v = new IPoint();
        iPoint_220v.setByqId(tz.getByqId());
        Float line_length_380v = 0f;    //  380v线路长度
        Float line_380v_1 = 0f;    //  380v线路长度
        Float line_380v_2 = 0f;    //  380v线路长度

        Float line_length_220v = 0f;    //  220v线路长度
        Float line_220v_1 = 0f;    //  220v线路长度
        Float line_220v_2 = 0f;    //  220v线路长度

        List<IPoint> iPointList_220v = iPointService.selectIPointList(iPoint_220v);
        if(iPointList_220v !=null){
            for (IPoint iPoints : iPointList_220v) {
                if (iPoints.getVoltage()!=null){
                    if (iPoints.getVoltage().equals("400v")){
                        if(iPoints.getType().equals("表箱") && iPoints.getInletLine() != null){
                            line_380v_1 = line_380v_1 + iPoints.getInletLine().floatValue();
                        }else if(iPoints.getSpan() != null){   //  档距不为空且点位类型不为表箱时（表箱的进户线长度不计算在总的导线长度，需要单独列出）
                            line_380v_2 = iPoints.getSpan().floatValue()+line_380v_2;
                        }
                        line_length_380v = line_380v_1 + line_380v_2;
                    }
                    if (iPoints.getVoltage().equals("220v")){
                        if(iPoints.getType().equals("表箱") && iPoints.getInletLine() != null){
                            line_220v_1 = iPoints.getInletLine().floatValue()+line_220v_1;
                        }else if(iPoints.getSpan() != null){   //  档距不为空且点位类型不为表箱时（表箱的进户线长度不计算在总的导线长度，需要单独列出）
                            line_220v_2 = iPoints.getSpan().floatValue()+line_220v_2;
                        }
                        line_length_220v = line_220v_1 + line_220v_2;
                    }
                }
            }
        }


        for (int i = 0; i < 2; i++) {
            TZ tzNew = new TZ();
            if(i==0){
                tzNew.setDeviceName("导线380");
                tzNew.setNewRu("千米");
                tzNew.setNum(String.valueOf(div(line_length_380v,1000,2)));
            }else{
                tzNew.setDeviceName("导线220");
                tzNew.setNewRu("千米");
                tzNew.setNum(String.valueOf(div(line_length_220v,1000,2)));
            }
            tzs.add(tzNew);
        }
//  线路
        ILine iLine1 = new ILine();
        iLine1.setByqId(tz.getByqId());
        List<ILine> iLineList = iLineService.selectILineList(iLine1);
        IPoint iPoint = new IPoint();
        iPoint.setByqId(tz.getByqId());
//        iPoint.setLineId(iLineList.get(i).getId());
        List<IPoint> iPointList12 = new ArrayList<>();

        for (ILine iLine : iLineList) {
            iPoint.setLineId(iLine.getId());
            iPointList12 = iPointService.selectIPointList(iPoint);
            Double oneNum = 0d , twoNum = 0d ;
            List<IMaterial> iMaterials = new ArrayList<>();
            String newMater = "";
            StringBuffer sbf = new StringBuffer();
            List<String> list1 = new ArrayList();
            for (IPoint point : iPointList12) {
                if(point.getSpan() != null){
                    oneNum += point.getSpan().doubleValue();
                }else if(point.getInletLine() != null){
                    twoNum += point.getInletLine().doubleValue();
                }
                IMaterial iMaterial = new IMaterial();
                iMaterial.setByqId(tz.getByqId());
                iMaterial.setPointId(point.getId());
                iMaterials = iMaterialService.selectIMaterialList(iMaterial);


                if(iMaterials.size()!=0){
                    for (IMaterial material : iMaterials) {
                        if(material.getBigType().equals("架空绝缘导线") || material.getBigType().equals("钢芯铝绞线") ||
                                material.getBigType().equals("0.4kV电缆") || material.getBigType().equals("交联电缆")){
                            list1.add(material.getName());
                        }
                    }

                }

            }

            if(list1.size()!=0){
                List<String> uts = removeDuplicate(list1);
                for (String ut : uts) {
                    sbf.append(ut);
                    sbf.append(";");
                }
                newMater = sbf.substring(0,sbf.lastIndexOf(";"));
                iLine.setNewMater(newMater);
            }


            iLine.setSunTotal(new BigDecimal(oneNum+twoNum));
        }
        for (ILine iLine : iLineList) {
            TZ tzNew = new TZ();
            tzNew.setDeviceName(iLine.getName());
            tzNew.setNewRu("千米");
            if (iLine.getSunTotal().doubleValue()!=0) tzNew.setNum(String.valueOf(div(iLine.getSunTotal().doubleValue(),1000 ,2)));
            if(iLine.getNewMater()!= null) tzNew.setModel(iLine.getNewMater());
            tzs.add(tzNew);
        }




        return getDataTable(tzs);
    }


    /**
     *  杆塔明细table
     */
    @PostMapping("/listGT")
    @ResponseBody
    public TableDataInfo listGT( GT gt)
    {


        List<GT> gts = new ArrayList<>();

        IPoint iPoint = new IPoint();
        iPoint.setByqId(gt.getByqId());
        List<IPoint> iPointList = iPointService.selectIPointList(iPoint);
        List<IPoint> iPointList22 = new ArrayList<>();

        for (IPoint point : iPointList) {
            if(point.getType().equals("杆塔") || point.getType().equals("同杆架设")){
                iPointList22.add(point);
            }
        }
//        startPage();
        for (IPoint point : iPointList22) {
            GT gt1 = new GT();
            ILine iLine = iLineService.selectILineById(point.getLineId());
            IMaterial iMaterial = new IMaterial();
            iMaterial.setPointId(point.getId());
            List<IMaterial> iMaterialList = iMaterialService.selectIMaterialList(iMaterial);
            List<IMaterial> iMaterialList11 = new ArrayList<>();

            for (IMaterial material : iMaterialList) {
                if(material.getBigType().equals("架空绝缘导线") || material.getBigType().equals("钢芯铝绞线") ||
                        material.getBigType().equals("0.4kV电缆") || material.getBigType().equals("交联电缆")){
                    iMaterialList11.add(material);
                }
            }



            List<IMaterial> iMaterialList22 = new ArrayList<>();
            List<IMaterial> iMaterialList33 = new ArrayList<>();
            IPole iPole = new IPole();
            iPole.setPId(point.getId());
            List<IPole> iPoleList = iPoleService.selectIPoleList(iPole);
            if(iPoleList.size() == 0){
                iPole.setPId(point.getPoleId());
                iPoleList = iPoleService.selectIPoleList(iPole);
            }
            for (IMaterial material : iMaterialList) {
                if(material.getBigType().equals("横担")){
                    iMaterialList22.add(material);
                }
            }
            for (IMaterial material : iMaterialList) {
                if(material.getBigType().equals("绝缘子")){
                    iMaterialList33.add(material);
                }
            }


            //  型号
            String newName = "";
            if(iMaterialList11.size()>0){
                StringBuffer materName = new StringBuffer();
                for (IMaterial material : iMaterialList11) {
                    materName.append(material.getName());
                    materName.append(";");
                }
                //  取消末尾分号
                newName = materName.substring(0,materName.lastIndexOf(";"));
            }

            gt1.setLineName(iLine.getName());
            gt1.setCode(point.getCode());
            gt1.setVoltage(point.getVoltage());
            gt1.setGtType(iPoleList.get(0).getType());
            if(point.getPoleHeight()!= null){
                if(point.getPoleHeight().equals("8米")) gt1.setHeight8("1");
                if(point.getPoleHeight().equals("10米")) gt1.setHeight10("1");
                if(point.getPoleHeight().equals("12米") || point.getPoleHeight().equals("12米特型")) gt1.setHeight12("1");
                if(point.getPoleHeight().equals("15米") || point.getPoleHeight().equals("15米特型")) gt1.setHeight15("1");
                if(point.getPoleHeight().equals("18米") || point.getPoleHeight().equals("18米特型")) gt1.setHeight18("1");
            }
            gt1.setLineModel(newName);
            gt1.setSpan(point.getSpan().toString());
            /*if(iMaterialList22.size() != 0 && iMaterialList22.get(0).getBigType().equals("横担")){
                if(iMaterialList22.get(0).getLable().equals("1500"))gt1.setHd1500(iMaterialList22.get(0).getCount().toString());
                if(iMaterialList22.get(0).getLable().equals("1500"))gt1.setHd1500(iMaterialList22.get(0).getCount().toString());
                if(iMaterialList22.get(0).getLable().equals("1630"))gt1.setHd1500(iMaterialList22.get(0).getCount().toString());
                if(iMaterialList22.get(0).getLable().equals("1750"))gt1.setHd1500(iMaterialList22.get(0).getCount().toString());
                if(iMaterialList22.get(0).getLable().equals("1800"))gt1.setHd1500(iMaterialList22.get(0).getCount().toString());
            }*/

            if(iMaterialList22.size() != 0){
                for (IMaterial material : iMaterialList22) {
                    if(material.getBigType().equals("横担")){
                        if(material.getLable().equals("1500"))gt1.setHd1500(String.valueOf(material.getCount().intValue()));
                        if(material.getLable().equals("1630"))gt1.setHd1630(String.valueOf(material.getCount().intValue()));
                        if(material.getLable().equals("1750"))gt1.setHd1750(String.valueOf(material.getCount().intValue()));
                        if(material.getLable().equals("1800"))gt1.setHd1800(String.valueOf(material.getCount().intValue()));
                    }
                }
            }




            if(point.getPullNum() != null && point.getPullNum() >0 ){
                gt1.setPullNum(point.getPullNum().toString());
            }
            /*if(iMaterialList33.size() != 0 && iMaterialList33.get(0).getBigType().equals("绝缘子")){
                if(iMaterialList33.get(0).getMidType().equals("针式")) gt1.setCpZhen(iMaterialList33.get(0).getCount().toString());
                if(iMaterialList33.get(0).getMidType().equals("柱式")) gt1.setCpZhen(iMaterialList33.get(0).getCount().toString());
                if(iMaterialList33.get(0).getMidType().equals("碟式")) gt1.setCpZhen(iMaterialList33.get(0).getCount().toString());
                if(iMaterialList33.get(0).getMidType().equals("悬式")) gt1.setCpZhen(iMaterialList33.get(0).getCount().toString());
            }*/

            if(iMaterialList33.size() != 0){
                for (IMaterial material : iMaterialList33) {
                    if(material.getBigType().equals("绝缘子")){
                        if(material.getMidType().equals("针式"))gt1.setCpZhen(String.valueOf(material.getCount().intValue()));
                        if(material.getMidType().equals("柱式"))gt1.setCpZhu(String.valueOf(material.getCount().intValue()));
                        if(material.getMidType().equals("碟式"))gt1.setCpDie(String.valueOf(material.getCount().intValue()));
                        if(material.getMidType().equals("悬式"))gt1.setCpXuan(String.valueOf(material.getCount().intValue()));
                    }
                }
            }

            gts.add(gt1);

        }


        return getDataTable(gts);
    }

    /**
     *  表箱明细table
     */
    @PostMapping("/listBX")
    @ResponseBody
    public TableDataInfo listBX(BX bx)
    {

//        startPage();
        List<BX> bxes = new ArrayList<>();
        IBoxes iBoxes = new IBoxes();
        iBoxes.setByqId(bx.getByqId());
        List<IBoxes> iBoxesList = iBoxesService.getBoxesForByqId(iBoxes);
        for (IBoxes boxes : iBoxesList) {
            IPoint iPoint = iPointService.selectIPointById(boxes.getPId());
            ILine iLine = iLineService.selectILineById(iPoint.getLineId());
            boxes.setLineId(iLine.getName());
            if(iPoint.getVoltage().equals("400v")){
                boxes.setRunCode("380v");
            }else if(iPoint.getVoltage().equals("220v")){
                boxes.setRunCode(iPoint.getVoltage());
            }
        }
        for (IBoxes boxes : iBoxesList) {
            BX bx1 = new BX();
            IPoint iPoint = iPointService.selectIPointById(boxes.getPId());
            bx1.setLineName(boxes.getLineId());
            bx1.setPointCode(iPoint.getCode());
            bx1.setVoltage(iPoint.getVoltage());
            if(boxes.getNum() != null && boxes.getNum().equals("单相")){
                bx1.setDx("1");
            }if(boxes.getNum() != null && boxes.getNum().equals("三相")){
                bx1.setSx("1");
            }if(boxes.getWs() != null && boxes.getWs().equals("1表位")){
                bx1.setWs1("1");
            }if(boxes.getWs() != null && boxes.getWs().equals("2表位")){
                bx1.setWs2("1");
            }if(boxes.getWs() != null && boxes.getWs().equals("4表位")){
                bx1.setWs4("1");
            }if(boxes.getWs() != null && boxes.getWs().equals("6表位")){
                bx1.setWs6("1");
            }if(boxes.getWs() != null && boxes.getWs().equals("9表位")){
                bx1.setWs9("1");
            }if(boxes.getWs() != null && boxes.getWs().equals("12表位")){
                bx1.setWs12("1");
            }
            bx1.setInstall_count(boxes.getInstallCount().toString());

            bxes.add(bx1);
        }
        

        return getDataTable(bxes);
    }


    /**
     *  表计明细table
     */
    @PostMapping("/listBJ")
    @ResponseBody
    public TableDataInfo list( BJ bj)
    {

//         todo 分页

//        startPage();
        List<BJ> bjs = new ArrayList<>();

        IDevice iDevice = new IDevice();
        iDevice.setByqId(bj.getByqId());
        List<IDevice> iDeviceList = iDeviceService.getBigType(iDevice);
//        startPage();
        List<IDevice> iDeviceList22 = new ArrayList<>();
        for (IDevice device : iDeviceList) {
            if(device.getBigType().equals("电能表")){
                iDeviceList22.add(device);
            }
        }

        for (IDevice device : iDeviceList22) {
            IPoint iPoint = iPointService.selectIPointById(device.getPointId());

            BJ bj1 = new BJ();
            KBj kBj = new KBj();
            kBj.setByqId(device.getByqId());
            kBj.setBoxId(device.getId());
            List<KBj> kBjList = kBjService.selectKBjList(kBj);


            bj1.setPointCode(iPoint.getCode());
            bj1.setModel(device.getName());
            if(kBjList.size() > 0){
                bj1.setName(kBjList.get(0).getName());
                bj1.setCode(kBjList.get(0).getCode());
                bj1.setbCode(kBjList.get(0).getBCode());
                if(kBjList.get(0).getType() != null){
                    if(kBjList.get(0).getType().equals("关口表")){
                        bj1.setType2("1");
                    }if(kBjList.get(0).getType().equals("用户表")){
                        bj1.setType1("1");
                    }

                }
            }


            if(device.getName().indexOf("单相") != -1){
                bj1.setDx("1");
            }if(device.getName().indexOf("三相") != -1){
                bj1.setSx("1");
            }

            bjs.add(bj1);
        }

        return getDataTable(bjs);
    }

    /**
     * 资产概览
     * @param zc
     * @return
     * @Time 2019-9-2 11:33:10
     */
    @PostMapping("/listZC")
    @ResponseBody
    public TableDataInfo listZC(ZC zc)
    {
        IMaterial iMaterial = new IMaterial();
        iMaterial.setByqId(zc.getByqId());
        List<ZC> zcList = new ArrayList<>();

        //  点位信息
        IPoint iPoint = new IPoint();
        iPoint.setByqId(zc.getByqId());
        List<IPoint> iPointList = iPointService.selectIPointList(iPoint);

        //  设备信息
        IDevice iDevices = new IDevice();
        iDevices.setByqId(zc.getByqId());
        List<IDevice> iDeviceLists = iDeviceService.getBigType(iDevices);

        //  架空线
        List<IMaterial> iMaterialListJK = iMaterialService.getBigTypeForJK(iMaterial);
        //  电缆线
        List<IMaterial> iMaterialListDL = iMaterialService.getBigTypeForDL(iMaterial);

        int jkSize = iMaterialListJK.size();
        int dlSize = iMaterialListDL.size();
        //  1、两种线路都有的情况
        if(jkSize!=0 && dlSize!=0){
            //  1.1 架空线路多于电缆线路
            if(jkSize>dlSize){
                //  架空线路
                for (int i = 0; i < iMaterialListJK.size(); i++) {
                    Double lingJK = 0D;                         //  架空线长度
                    ZC zcs = new ZC();
                    zcs.setJkgg(iMaterialListJK.get(i).getName());                  //  架空线路规格
                    //  线路长度
                    String[] iw = iMaterialListJK.get(i).getPointId().split(",");     //  点位
                    Double saw = 0D;
                    for (String s : iw) {
                        IPoint iPoint1 = iPointService.selectIPointById(s);
                        if(iPoint1 != null && !iPoint1.getType().equals("变压器")){
                            if(iPoint1.getType().equals("表箱"))
                                saw = iPoint1.getInletLine().doubleValue()+saw;
                            else
                                saw = iPoint1.getSpan().doubleValue()+saw;
                        }
                    }
                    lingJK += saw;
                    zcs.setJksl(String.valueOf(div(lingJK, 1000, 2)));      //  架空线路数量

                    //  电缆线路
                    for (int j = i; j < iMaterialListDL.size(); j++) {
                        Double lingDL = 0D;                         //  电缆线长度
                        zcs.setDlxl(iMaterialListDL.get(j).getName());              //  电缆线路规格
                        //  线路长度
                        String[] iw2 = iMaterialListDL.get(j).getPointId().split(",");     //  点位
                        Double saw2 = 0D;
                        for (String s : iw2) {
                            IPoint iPoint1 = iPointService.selectIPointById(s);
                            if(iPoint1 != null && !iPoint1.getType().equals("变压器")){
                                if(iPoint1.getType().equals("表箱"))
                                    saw2 = iPoint1.getInletLine().doubleValue()+saw2;
                                else
                                    saw2 = iPoint1.getSpan().doubleValue()+saw2;
                            }
                        }
                        lingDL += saw2;
                        zcs.setDlsl(String.valueOf(div(lingDL, 1000, 2)));
                        break;
                    }
                    zcList.add(zcs);
                }
            }
            //  1.2 电缆线路多于等于架空线路
            if(dlSize>=jkSize){
                //  电缆线路
                for (int i = 0; i < iMaterialListDL.size(); i++) {
                    Double lingDL = 0D;                         //  电缆线长度
                    ZC zcs = new ZC();
                    zcs.setDlxl(iMaterialListDL.get(i).getName());                      //  电缆线路规格
                    //  线路长度
                    String[] iw = iMaterialListDL.get(i).getPointId().split(",");     //  点位
                    Double saw = 0D;
                    for (String s : iw) {
                        IPoint iPoint1 = iPointService.selectIPointById(s);
                        if(iPoint1 != null && !iPoint1.getType().equals("变压器")){
                            if(iPoint1.getType().equals("表箱"))
                                saw = iPoint1.getInletLine().doubleValue()+saw;
                            else
                                saw = iPoint1.getSpan().doubleValue()+saw;
                        }
                    }
                    lingDL += saw;
                    zcs.setDlsl(String.valueOf(div(lingDL, 1000, 2)));

                    //  架空线路
                    for (int j = i; j < iMaterialListJK.size(); j++) {
                        Double lingJK = 0D;                         //  架空线长度
                        zcs.setJkgg(iMaterialListJK.get(j).getName());                  //  架空线路规格
                        //  线路长度
                        String[] iw2 = iMaterialListJK.get(j).getPointId().split(",");     //  点位
                        Double saw2 = 0D;
                        for (String s : iw2) {
                            IPoint iPoint1 = iPointService.selectIPointById(s);
                            if(iPoint1 != null && !iPoint1.getType().equals("变压器")){
                                if(iPoint1.getType().equals("表箱"))
                                    saw2 = iPoint1.getInletLine().doubleValue()+saw2;
                                else
                                    saw2 = iPoint1.getSpan().doubleValue()+saw2;
                            }
                        }
                        lingJK += saw2;
                        zcs.setJksl(String.valueOf(div(lingJK, 1000, 2)));
                        break;
                    }
                    zcList.add(zcs);
                }
            }
        }

        //  2、一种线路有，一种线路无的情况
        if(jkSize!=0 && dlSize==0){ //  架空线路不为空，电缆线路为空
            for (int i = 0; i < iMaterialListJK.size(); i++) {
                Double lingJK = 0D;                         //  架空线长度
                ZC zcs = new ZC();
                zcs.setJkgg(iMaterialListJK.get(i).getName());                  //  架空线路规格
                //  线路长度
                String[] iw = iMaterialListJK.get(i).getPointId().split(",");     //  点位
                Double saw = 0D;
                for (String s : iw) {
                    IPoint iPoint1 = iPointService.selectIPointById(s);
                    if(iPoint1 != null && !iPoint1.getType().equals("变压器")){
                        if(iPoint1.getType().equals("表箱"))
                            saw = iPoint1.getInletLine().doubleValue()+saw;
                        else
                            saw = iPoint1.getSpan().doubleValue()+saw;
                    }
                }
                lingJK += saw;
                zcs.setJksl(String.valueOf(div(lingJK, 1000, 2)));
                zcList.add(zcs);
            }
        }
        if(jkSize==0 && dlSize!=0){ //  电缆线路不为空，架空线路为空
            for (int i = 0; i < iMaterialListDL.size(); i++) {
                Double lingDL = 0D;                         //  电缆线长度
                ZC zcs = new ZC();
                zcs.setDlxl(iMaterialListDL.get(i).getName());                      //  电缆线路规格
                //  线路长度
                String[] iw = iMaterialListDL.get(i).getPointId().split(",");     //  点位
                Double saw = 0D;
                for (String s : iw) {
                    IPoint iPoint1 = iPointService.selectIPointById(s);
                    if(iPoint1 != null && !iPoint1.getType().equals("变压器")){
                        if(iPoint1.getType().equals("表箱"))
                            saw = iPoint1.getInletLine().doubleValue()+saw;
                        else
                            saw = iPoint1.getSpan().doubleValue()+saw;
                    }
                }
                lingDL += saw;
                zcs.setDlsl(String.valueOf(div(lingDL, 1000, 2)));
                zcList.add(zcs);
            }
        }

        //  供电所、台区、所属馈路
        BByq bByq = new BByq();
        bByq.setId(zc.getByqId());
        List<BByq> byqList = bByqService.selectBByqList(bByq);

        //  其余信息组合
        if(zcList!=null){
            for (int i = 0; i < zcList.size(); i++) {
                if(i==0){
                    String lingModleJK = "";                    //  架空线规格型号
                    String lingModleDL = "";                    //  电缆线规格型号
                    Double v380 = 0D;                           //  380v线路长度
                    Double v220 = 0D;                           //  220v线路长度
                    Double lineCount = 0D;                      //  线路长度合计

                    Integer poleHeight8 = 0;                    //  8米杆高基数
                    Integer poleHeight10 = 0;                   //  10米杆高基数
                    Integer poleHeight12 = 0;                   //  12米杆高基数
                    Integer poleHeight12_T = 0;                 //  12米特性杆杆高基数
                    Integer poleHeight15 = 0;                   //  15米杆高基数
                    Integer poleHeight15_T = 0;                 //  15米特性杆杆高基数
                    Integer poleHeight18 = 0;                   //  18米杆高基数
                    Integer poleHeight18_T = 0;                 //  18米特性杆杆高基数

                    Integer sumTotal = 0;                       //  杆高总和
                    String poleShape = "";                      //  杆塔形状
                    String manufacturer = "";                   //  生产厂家
                    String comDate = "";                        //  投运日期

                    //  单相户表(智能型、普通型)、单相表箱、三相户表(智能型、普通型)、三相表箱
                    Integer oneSurfaceSmart = 0;                //  单相户表--智能型数量
                    Integer oneBox_one = 0;                     //  单相户表--1表位
                    Integer oneBox_two = 0;                     //  单相户表--2表位
                    Integer oneBox_four = 0;                    //  单相户表--4表位
                    Integer oneBox_six = 0;                     //  单相户表--6表位
                    Integer oneBox_nine = 0;                    //  单相户表--9表位
                    Integer oneBox_twelve = 0;                  //  单相户表--12表位
                    Integer oneBox_total = 0;                   //  单相户表--合计
                    Integer threeSurfaceSmart = 0;              //  三相户表--智能型数量
                    Integer threeBox = 0;                       //  三相表箱数量

                    Integer concentrator = 0;                   //  集中器数量
                    Integer mutualInductor = 0;                 //  互感器数量
                    Integer lowBox = 0;                         //  低压电缆分支箱数量
                    Integer lowCabinet = 0;                     //  成套低压配电柜数量

                    Float line_length_380v = 0f;                //  380v线路长度
                    Float line_380v_1 = 0f;                     //  380v线路长度
                    Float line_380v_2 = 0f;                     //  380v线路长度

                    Float line_length_220v = 0f;                //  220v线路长度
                    Float line_220v_1 = 0f;                     //  220v线路长度
                    Float line_220v_2 = 0f;                     //  220v线路长度

                    String dxhb = null;                         //  单相户表
                    String sxhb = null;                         //  三相户表

                    if(iPointList !=null){
                        for (IPoint iPoints : iPointList) {
                            //  分电压线路长度
                            if (iPoints.getVoltage()!=null){
                                if (iPoints.getVoltage().equals("400v")){
                                    if(iPoints.getType().equals("表箱") && iPoints.getInletLine() != null){
                                        line_380v_1 = line_380v_1 + iPoints.getInletLine().floatValue();
                                    }else if(iPoints.getSpan() != null){   //  档距不为空且点位类型不为表箱时（表箱的进户线长度不计算在总的导线长度，需要单独列出）
                                        line_380v_2 = iPoints.getSpan().floatValue()+line_380v_2;
                                    }
                                    line_length_380v = line_380v_1 + line_380v_2;
                                }
                                if (iPoints.getVoltage().equals("220v")){
                                    if(iPoints.getType().equals("表箱") && iPoints.getInletLine() != null){
                                        line_220v_1 = iPoints.getInletLine().floatValue()+line_220v_1;
                                    }else if(iPoints.getSpan() != null){   //  档距不为空且点位类型不为表箱时（表箱的进户线长度不计算在总的导线长度，需要单独列出）
                                        line_220v_2 = iPoints.getSpan().floatValue()+line_220v_2;
                                    }
                                    line_length_220v = line_220v_1 + line_220v_2;
                                }
                            }

                            //  分属杆高基数
                            if (iPoints.getType().equals("杆塔")) {
                                if (iPoints.getPoleHeight().equals("8米")) {
                                    poleHeight8 = ++poleHeight8;
                                } else if (iPoints.getPoleHeight().equals("10米")) {
                                    poleHeight10 = ++poleHeight10;
                                } else if (iPoints.getPoleHeight().equals("12米")) {
                                    poleHeight12 = ++poleHeight12;
                                } else if (iPoints.getPoleHeight().equals("12米特型")) {
                                    poleHeight12_T = ++poleHeight12_T;
                                } else if (iPoints.getPoleHeight().equals("15米")) {
                                    poleHeight15 = ++poleHeight15;
                                } else if (iPoints.getPoleHeight().equals("15米特型")) {
                                    poleHeight15_T = ++poleHeight15_T;
                                } else if (iPoints.getPoleHeight().equals("18米")) {
                                    poleHeight18 = ++poleHeight18;
                                } else if (iPoints.getPoleHeight().equals("18米特型")) {
                                    poleHeight18_T = ++poleHeight18_T;
                                }
                            }

                            //  三相表箱
                            IBoxes iBoxes = new IBoxes();
                            iBoxes.setPId(iPoints.getId());
                            List<IBoxes> iBoxesList = iBoxesService.selectIBoxesList(iBoxes);
                            for (IBoxes boxes : iBoxesList) {
                                if(boxes.getNum() != null){
                                    if(boxes.getNum().equals("三相")){        //  三相表箱个数
                                        threeBox = ++threeBox;
                                    }
                                }
                            }
                        }
                        //  杆基总和
                        sumTotal = poleHeight8 + poleHeight10 + poleHeight12 + poleHeight12_T + poleHeight15 + poleHeight15_T + poleHeight18 + poleHeight18_T;
                    }

                    //  单相户表(智能型、普通型)、单相表箱、三相户表(智能型、普通型)、三相表箱
                    dxhb = iBoxesService.getCountsListForNum(zc.getByqId(), "单相");  //  单相户表
                    sxhb = iBoxesService.getCountsListForNum(zc.getByqId(), "三相");  //  三相户表

                    //  单相表箱表位
                    oneBox_one = iBoxesService.getCountsForType(zc.getByqId(),"单相","1表位");
                    oneBox_two = iBoxesService.getCountsForType(zc.getByqId(),"单相","2表位");
                    oneBox_four = iBoxesService.getCountsForType(zc.getByqId(),"单相","4表位");
                    oneBox_six = iBoxesService.getCountsForType(zc.getByqId(),"单相","6表位");
                    oneBox_nine = iBoxesService.getCountsForType(zc.getByqId(),"单相","9表位");
                    oneBox_twelve = iBoxesService.getCountsForType(zc.getByqId(),"单相","12表位");

                    //  单相表箱合计
                    if(oneBox_one==null) oneBox_one=0;if(oneBox_two==null) oneBox_two=0;if(oneBox_four==null) oneBox_four=0;
                    if(oneBox_six==null) oneBox_six=0;if(oneBox_nine==null) oneBox_nine=0;if(oneBox_twelve==null) oneBox_twelve=0;
                    oneBox_total = oneBox_one + oneBox_two + oneBox_four + oneBox_six + oneBox_nine + oneBox_twelve;

                    //  设备
                    for (IDevice device : iDeviceLists) {
                        if (device.getBigType().equals("分支箱")) {
                            if (device.getName().indexOf("分支箱") != -1) {
                                lowBox = ++lowBox;
                            }
                        } else if (device.getBigType().equals("低压配电柜/盘")) {
                            if (device.getName().indexOf("低压配电柜") != -1) {
                                lowCabinet = ++lowCabinet;
                            }
                        } else if (device.getBigType().equals("采集通信设备")) {
                            if (device.getName().indexOf("集中器") != -1) {
                                concentrator = ++concentrator;
                            }
                        } else if (device.getBigType().equals("低压电流互感器")) {
                            if (device.getName().indexOf("低压电流互感器") != -1) {
                                mutualInductor = ++mutualInductor;
                            }
                        }
                    }

                    for (BByq byq : byqList) {
                        Dept dept = deptService.selectDeptById(Long.parseLong(byq.getDeptId()));
                        zcList.get(i).setDeptId(dept.getDeptName());       //  供电所
                        zcList.get(i).setByqId(byq.getName());             //  台区
                        zcList.get(i).setLine10kv(byq.getLine10kvName()); //  所属馈路
                    }
                    //  380v线路长度
                    if(line_length_380v!=0)
                        zcList.get(i).setLine380v(String.valueOf(div(line_length_380v, 1000, 2)));
                    else zcList.get(i).setLine380v("");
                    //  220v线路长度
                    if(line_length_220v!=0)
                        zcList.get(i).setLine220v(String.valueOf(div(line_length_220v, 1000, 2)));
                    else zcList.get(i).setLine220v("");
                    //  线路长度合计
                    if((line_length_380v+line_length_220v)!=0)
                        zcList.get(i).setLineSum(String.valueOf(div((line_length_380v+line_length_220v), 1000, 2)));
                    else zcList.get(i).setLineSum("");
                    //  8米杆基数
                    if(poleHeight8!=0)zcList.get(i).setGt8(poleHeight8.toString());else zcList.get(i).setGt8("");
                    //  10米杆基数
                    if(poleHeight10!=0)zcList.get(i).setGt10(poleHeight10.toString());else zcList.get(i).setGt10("");
                    //  12米杆基数
                    if(poleHeight12!=0)zcList.get(i).setGt12(poleHeight12.toString());else zcList.get(i).setGt12("");
                    //  12米特型杆基数
                    if(poleHeight12_T!=0)zcList.get(i).setGt12t(poleHeight12_T.toString());else zcList.get(i).setGt12t("");
                    //  15米杆基数
                    if(poleHeight15!=0)zcList.get(i).setGt15(poleHeight15.toString());else zcList.get(i).setGt15("");
                    //  15米特型杆基数
                    if(poleHeight15_T!=0)zcList.get(i).setGt15t(poleHeight15_T.toString());else zcList.get(i).setGt15t("");
                    //  18米杆基数
                    if(poleHeight18!=0)zcList.get(i).setGt18(poleHeight18.toString());else zcList.get(i).setGt18("");
                    //  18米特型杆基数
                    if(poleHeight18_T!=0)zcList.get(i).setGt18t(poleHeight18_T.toString());else zcList.get(i).setGt18t("");
                    //  杆基总和
                    if(sumTotal!=0)zcList.get(i).setGtSum(sumTotal.toString());else zcList.get(i).setGtSum("");
                    //  单相户表
                    if(dxhb!=null)zcList.get(i).setDxHb(dxhb);else zcList.get(i).setDxHb("");
                    //  单相表箱1表位
                    if(oneBox_one!=0)zcList.get(i).setBxOne(oneBox_one.toString());else zcList.get(i).setBxOne("");
                    //  2表位
                    if(oneBox_two!=0)zcList.get(i).setBxTwo(oneBox_two.toString());else zcList.get(i).setBxTwo("");
                    //  4表位
                    if(oneBox_four!=0)zcList.get(i).setBxFour(oneBox_four.toString());else zcList.get(i).setBxFour("");
                    //  6表位
                    if(oneBox_six!=0)zcList.get(i).setBxSix(oneBox_six.toString());else zcList.get(i).setBxSix("");
                    //  9表位
                    if(oneBox_nine!=0)zcList.get(i).setBxNine(oneBox_nine.toString());else zcList.get(i).setBxNine("");
                    //  12表位
                    if(oneBox_twelve!=0)zcList.get(i).setBxTwelve(oneBox_twelve.toString());else zcList.get(i).setBxTwelve("");
                    //  单相表箱合计
                    if(oneBox_total!=0)zcList.get(i).setBxSum(oneBox_total.toString());else zcList.get(i).setBxSum("");
                    //  三相户表
                    if(sxhb!=null)zcList.get(i).setSxHb(sxhb);else zcList.get(i).setSxHb("");
                    //  三相表箱
                    if(threeBox!=0)zcList.get(i).setSxbx(threeBox.toString());else zcList.get(i).setSxbx("");
                    //  集中器
                    if(concentrator!=0)zcList.get(i).setJzq(concentrator.toString());else zcList.get(i).setJzq("");
                    //  互感器
                    if(mutualInductor!=0)zcList.get(i).setHgq(mutualInductor.toString());else zcList.get(i).setHgq("");
                    //  分支箱
                    if(lowBox!=0)zcList.get(i).setFzx(lowBox.toString());else zcList.get(i).setFzx("");
                    //  配电柜
                    if(lowCabinet!=0)zcList.get(i).setPdg(lowCabinet.toString());else zcList.get(i).setPdg("");
                }
            }
        }

        return getDataTable(zcList);
    }


    /**
     *  资产概览
     *  @Time 2019-6-2 11:32:29
     */
//    @PostMapping("/listZC11")
//    @ResponseBody
//    public TableDataInfo listZC11(ZC zc)
//    {
//
////        startPage();
//        List<ZC> zcs = new ArrayList<>();
//
//        BByq bByq = new BByq();
//        bByq.setId(zc.getByqId());
//        List<BByq> byqList = bByqService.selectBByqList(bByq);
////        ILine iLines = new ILine();
////        iLines.setByqId(id);
////        List<ILine> ilist = iLineService.selectILineList(iLines);
//
//        IPoint iPoint = new IPoint();
//        iPoint.setByqId(zc.getByqId());
//        List<IPoint> iPointList = iPointService.selectIPointList(iPoint);
//
//        //  以电缆或者架空线的数量循环
//        IDevice iDevices = new IDevice();
//        iDevices.setByqId(zc.getByqId());
//        List<IDevice> iDeviceLists = iDeviceService.getBigType(iDevices);
//
//        IMaterial iMaterial = new IMaterial();
//        iMaterial.setByqId(zc.getByqId());
//        List<IMaterial> iMaterialList22 = iMaterialService.getBigType(iMaterial);
//
//        /*//  400v导线长度
//        Float i400v = iPointService.totalLine(zc.getByqId(),"400v");
//
//        //  220v导线长度
//        Float i220v = iPointService.totalLine(zc.getByqId(),"220v");
//
//        if(i400v == null)i400v = 0F ;
//        if(i220v == null)i220v = 0F ;
//
//        float i42 = i400v+i220v;*/
//
//
//
//        IPoint iPoint_220v = new IPoint();
//        iPoint_220v.setByqId(zc.getByqId());
//        Float line_length_380v = 0f;    //  380v线路长度
//        Float line_380v_1 = 0f;    //  380v线路长度
//        Float line_380v_2 = 0f;    //  380v线路长度
//
//        Float line_length_220v = 0f;    //  220v线路长度
//        Float line_220v_1 = 0f;    //  220v线路长度
//        Float line_220v_2 = 0f;    //  220v线路长度
//
//        List<IPoint> iPointList_220v = iPointService.selectIPointList(iPoint_220v);
//        if(iPointList_220v !=null){
//            for (IPoint iPoints : iPointList_220v) {
//                if (iPoints.getVoltage()!=null){
//                    if (iPoints.getVoltage().equals("400v")){
//                        if(iPoints.getType().equals("表箱") && iPoints.getInletLine() != null){
//                            line_380v_1 = line_380v_1 + iPoints.getInletLine().floatValue();
//                        }else if(iPoints.getSpan() != null){   //  档距不为空且点位类型不为表箱时（表箱的进户线长度不计算在总的导线长度，需要单独列出）
//                            line_380v_2 = iPoints.getSpan().floatValue()+line_380v_2;
//                        }
//                        line_length_380v = line_380v_1 + line_380v_2;
//                    }
//                    if (iPoints.getVoltage().equals("220v")){
//                        if(iPoints.getType().equals("表箱") && iPoints.getInletLine() != null){
//                            line_220v_1 = iPoints.getInletLine().floatValue()+line_220v_1;
//                        }else if(iPoints.getSpan() != null){   //  档距不为空且点位类型不为表箱时（表箱的进户线长度不计算在总的导线长度，需要单独列出）
//                            line_220v_2 = iPoints.getSpan().floatValue()+line_220v_2;
//                        }
//                        line_length_220v = line_220v_1 + line_220v_2;
//                    }
//                }
//            }
//        }
//
//
//
//
//
//
//        List<IMaterial> iMaterialList = new ArrayList<>();
//        for (IMaterial material : iMaterialList22) {
//            if(material.getBigType().equals("架空绝缘导线") || material.getBigType().equals("钢芯铝绞线") ||
//                    material.getBigType().equals("0.4kV电缆") || material.getBigType().equals("交联电缆")){
//
//                String[] iw = material.getPointId().split(",");
//                Double saw = 0D;
//                for (String s : iw) {
//
//                    IPoint iPoint1 = iPointService.selectIPointById(s);
//                    if(iPoint1 != null){
//                        if(iPoint1.getType().equals("杆塔")){
//                            saw = iPoint1.getSpan().doubleValue()+saw;
//                        }else if(iPoint1.getType().equals("表箱")){
//                            saw = iPoint1.getInletLine().doubleValue()+saw;
//                        }else if(iPoint1.getType().equals("同杆架设")){
//                            saw = iPoint1.getSpan().doubleValue()+saw;
//                        }else if(iPoint1.getType().equals("下户点")){
//                            saw = iPoint1.getSpan().doubleValue()+saw;
//                        }else if(iPoint1.getType().equals("分支箱")){
//                            saw = iPoint1.getSpan().doubleValue()+saw;
//                        }
//                    }
//                }
//                material.setNewCounts(saw);
//                iMaterialList.add(material);
//
//            }
//        }
//        int ios = 0;
//        for (IMaterial material : iMaterialList) {
//            ZC zc1 = new ZC();
//
//            String lingModleJK = "";                    //  架空线规格型号
//            Double lingJK = 0D;                         //  架空线长度
//            String lingModleDL = "";                    //  电缆线规格型号
//            Double lingDL = 0D;                         //  电缆线长度
//            Double v380 = 0D;                           //  380v线路长度
//            Double v220 = 0D;                           //  220v线路长度
//            Double lineCount = 0D;                      //  线路长度合计
//
//            Integer poleHeight8 = 0;                    //  8米杆高基数
//            Integer poleHeight10 = 0;                   //  10米杆高基数
//            Integer poleHeight12 = 0;                   //  12米杆高基数
//            Integer poleHeight12_T = 0;                 //  12米特性杆杆高基数
//            Integer poleHeight15 = 0;                   //  15米杆高基数
//            Integer poleHeight15_T = 0;                   //  15米特性杆杆高基数
//            Integer poleHeight18 = 0;                   //  18米杆高基数
//            Integer poleHeight18_T = 0;                   //  18米特性杆杆高基数
//
//            Integer sumTotal = 0;                       //  杆高总和
//            String poleShape = "";                      //  杆塔形状
//            String manufacturer = "";                   //  生产厂家
//            String comDate = "";                        //  投运日期
//
//            //  单相户表(智能型、普通型)、单相表箱、三相户表(智能型、普通型)、三相表箱
//            Integer oneSurfaceSmart = 0;                //  单相户表--智能型数量
//            Integer oneBox_one = 0;                     //  单相户表--1表位
//            Integer oneBox_two = 0;                     //  单相户表--2表位
//            Integer oneBox_four = 0;                    //  单相户表--4表位
//            Integer oneBox_six = 0;                     //  单相户表--6表位
//            Integer oneBox_nine = 0;                    //  单相户表--9表位
//            Integer oneBox_twelve = 0;                  //  单相户表--12表位
//            Integer oneBox_total = 0;                   //  单相户表--合计
//            Integer threeSurfaceSmart = 0;              //  三相户表--智能型数量
//            Integer threeBox = 0;                       //  三相表箱数量
//
//            Integer concentrator = 0;                   //  集中器数量
//            Integer mutualInductor = 0;                 //  互感器数量
//            Integer lowBox = 0;                         //  低压电缆分支箱数量
//            Integer lowCabinet = 0;                     //  成套低压配电柜数量
//
//
//
//            if (material.getBigType().equals("架空绝缘导线")) {
//                lingModleJK = material.getName();
//                lingJK += material.getNewCounts();
//            } else if (material.getBigType().equals("钢芯铝绞线")) {
//                lingModleJK = material.getName();
//                lingJK += material.getNewCounts();
//            } else if (material.getBigType().equals("0.4kV电缆")) {
//                lingModleDL = material.getName();
//                lingDL += material.getNewCounts();
//            } else if (material.getBigType().equals("交联电缆")) {
//                lingModleDL = material.getName();
//                lingDL += material.getNewCounts();
//            }
//
//            for (IPoint point : iPointList) {
//                if (point.getVoltage() != null) {
//
//                    if (point.getVoltage().equals("400v") && ios == 0) {
//                        if(point.getType().equals("杆塔") || point.getType().equals("同杆架设"))
//                            v380 += point.getSpan().doubleValue();
//                        else if(point.getType().equals("表箱"))
//                            v380 += point.getInletLine().doubleValue();
//                    } else if (point.getVoltage().equals("220v")) {
//                        if(point.getType().equals("杆塔") || point.getType().equals("同杆架设"))
//                            v220 += point.getSpan().doubleValue();
//                        else if(point.getType().equals("表箱"))
//                            v220 += point.getInletLine().doubleValue();
//                    }
//                }
//
//                IBoxes iBoxes = new IBoxes();
//                iBoxes.setPId(point.getId());
//                List<IBoxes> iBoxesList = iBoxesService.selectIBoxesList(iBoxes);
//                for (IBoxes boxes : iBoxesList) {
//                    if(boxes.getNum() != null){
//                        if(boxes.getNum().equals("三相")){        //  三相表箱个数
//                            threeBox = ++threeBox;
//                        }
//                    }
//                }
//
//            }
//
//            oneBox_one = iBoxesService.getCountsForType(zc.getByqId(),"单相","1表位");
//            oneBox_two = iBoxesService.getCountsForType(zc.getByqId(),"单相","2表位");
//            oneBox_four = iBoxesService.getCountsForType(zc.getByqId(),"单相","4表位");
//            oneBox_six = iBoxesService.getCountsForType(zc.getByqId(),"单相","6表位");
//            oneBox_nine = iBoxesService.getCountsForType(zc.getByqId(),"单相","9表位");
//            oneBox_twelve = iBoxesService.getCountsForType(zc.getByqId(),"单相","12表位");
//
//            if(oneBox_one==null) oneBox_one=0;if(oneBox_two==null) oneBox_two=0;if(oneBox_four==null) oneBox_four=0;
//            if(oneBox_six==null) oneBox_six=0;if(oneBox_nine==null) oneBox_nine=0;if(oneBox_twelve==null) oneBox_twelve=0;
//            oneBox_total = oneBox_one + oneBox_two + oneBox_four + oneBox_six + oneBox_nine + oneBox_twelve;
//
//            //  线路长度合计
//            if (ios == 0) {
//                lineCount = v380 + v220;
//                if (ios == 0) {
//                    for (IPoint point : iPointList) {
//                        if (point.getType().equals("杆塔")) {
//                            if (point.getPoleHeight().equals("8米")) {
//                                poleHeight8 = ++poleHeight8;
//                            } else if (point.getPoleHeight().equals("10米")) {
//                                poleHeight10 = ++poleHeight10;
//                            } else if (point.getPoleHeight().equals("12米")) {
//                                poleHeight12 = ++poleHeight12;
//                            } else if (point.getPoleHeight().equals("12米特型")) {
//                                poleHeight12_T = ++poleHeight12_T;
//                            } else if (point.getPoleHeight().equals("15米")) {
//                                poleHeight15 = ++poleHeight15;
//                            } else if (point.getPoleHeight().equals("15米特型")) {
//                                poleHeight15_T = ++poleHeight15_T;
//                            } else if (point.getPoleHeight().equals("18米")) {
//                                poleHeight18 = ++poleHeight18;
//                            } else if (point.getPoleHeight().equals("18米特型")) {
//                                poleHeight18_T = ++poleHeight18_T;
//                            }
//                        }
//                    }
//                    sumTotal = poleHeight8 + poleHeight10 + poleHeight12 + poleHeight12_T + poleHeight15 + poleHeight15_T + poleHeight18 + poleHeight18_T;
//                }
//
//                //  杆基总和
//
//                //  杆塔形状、生产厂家、投运日期
//
//                //  单相户表(智能型、普通型)、单相表箱、三相户表(智能型、普通型)、三相表箱
//                String iBoxesList23 = null;
//                String iBoxesList34 = null;
//                if (ios == 0) {
//                    for (IDevice device : iDeviceLists) {
//
//                        if (device.getBigType().equals("分支箱")) {
//                            if (device.getName().indexOf("分支箱") != -1) {
//                                lowBox = ++lowBox;
//                            }
//                        } else if (device.getBigType().equals("低压配电柜/盘")) {
//                            if (device.getName().indexOf("低压配电柜") != -1) {
//                                lowCabinet = ++lowCabinet;
//                            }
//                        } else if (device.getBigType().equals("采集通信设备")) {
//                            if (device.getName().indexOf("集中器") != -1) {
//                                concentrator = ++concentrator;
//                            }
//                        } else if (device.getBigType().equals("低压电流互感器")) {
//                            if (device.getName().indexOf("低压电流互感器") != -1) {
//                                mutualInductor = ++mutualInductor;
//                            }
//                        }
//                    }
//                    iBoxesList23 = iBoxesService.getCountsListForNum(zc.getByqId(), "单相");
//                    iBoxesList34 = iBoxesService.getCountsListForNum(zc.getByqId(), "三相");
//                }
//                for (BByq byq : byqList) {
//                    Dept dept = deptService.selectDeptById(Long.parseLong(byq.getDeptId()));
//                    zc1.setDeptId(dept.getDeptName());       //  供电所
//                    zc1.setByqId(byq.getName());             //     台区
//                    zc1.setLine10kv(byq.getLine10kvName()); //  所属馈路
//                }
//
//                zc1.setJkgg(lingModleJK); //  架空线路规格
//                if (lingJK != 0) zc1.setJksl(String.valueOf(div(lingJK, 1000, 2)));
//                else zc1.setJksl("");//  架空线路数量
//                zc1.setDlxl(lingModleDL); //  电缆线路规格
//                if (lingDL != 0) zc1.setDlsl(String.valueOf(div(lingDL, 1000, 2)));
//                else zc1.setDlsl(""); //  电缆线路数量
//                if (v380 != 0) zc1.setLine380v(String.valueOf(div(line_length_380v, 1000, 2)));
//                else zc1.setLine380v(""); //  380v线路长度
//                if (v220 != 0) zc1.setLine220v(String.valueOf(div(line_length_220v, 1000, 2)));
//                else zc1.setLine220v(""); //  220v线路长度
//                if (lineCount != 0) zc1.setLineSum(String.valueOf(div((line_length_380v+line_length_220v), 1000, 2)));
//                else zc1.setLineSum(""); //  线路合计
//                if (poleHeight8 != 0) zc1.setGt8(poleHeight8.toString());
//                else zc1.setGt8("");//  8米杆
//                if (poleHeight10 != 0) zc1.setGt10(poleHeight10.toString());
//                else zc1.setGt10(""); //
//                if (poleHeight12 != 0) zc1.setGt12(poleHeight12.toString());
//                else zc1.setGt12(""); //
//                if (poleHeight12_T != 0) zc1.setGt12t(poleHeight12_T.toString());
//                else zc1.setGt12t(""); //
//                if (poleHeight15 != 0) zc1.setGt15(poleHeight15.toString());
//                else zc1.setGt15(""); //
//                if (poleHeight15_T != 0) zc1.setGt15t(poleHeight15_T.toString());
//                else zc1.setGt15t(""); //
//                if (poleHeight18 != 0) zc1.setGt18(poleHeight18.toString());
//                else zc1.setGt18(""); //
//                if (poleHeight18_T != 0) zc1.setGt18t(poleHeight18_T.toString());
//                else zc1.setGt18t(""); //
//                if (sumTotal != 0) zc1.setGtSum(sumTotal.toString());
//                else zc1.setGtSum(""); //  杆塔合计
//                zc1.setGtXz(""); //  形状
//                zc1.setFactroy(""); //  厂家
//                zc1.setTyTime(""); //  投运日期
//                if (iBoxesList23 != null) zc1.setDxHb(iBoxesList23);
//                else zc1.setDxHb(""); //  单相户表
//                if (oneBox_one != 0) zc1.setBxOne(oneBox_one.toString());
//                else zc1.setBxOne(""); //  1表位
//                if (oneBox_two != 0) zc1.setBxTwo(oneBox_two.toString());
//                else zc1.setBxTwo(""); //
//                if (oneBox_four != 0) zc1.setBxFour(oneBox_four.toString());
//                else zc1.setBxFour(""); //
//                if (oneBox_six != 0) zc1.setBxSix(oneBox_six.toString());
//                else zc1.setBxSix(""); //
//                if (oneBox_nine != 0) zc1.setBxNine(oneBox_nine.toString());
//                else zc1.setBxNine(""); //
//                if (oneBox_twelve != 0) zc1.setBxTwelve(oneBox_twelve.toString());
//                else zc1.setBxTwelve(""); //
//                if (oneBox_total != 0) zc1.setBxSum(oneBox_total.toString());
//                else zc1.setBxSum(""); //   表箱合计
//                if (iBoxesList34 != null) zc1.setSxHb(iBoxesList34);
//                else zc1.setSxHb(""); //    三相表计
//                if (threeBox != 0) zc1.setSxbx(threeBox.toString());
//                else zc1.setSxbx(""); //    三相表箱
//                if (concentrator != 0) zc1.setJzq(concentrator.toString());
//                else zc1.setJzq(""); //     集中器
//                if (mutualInductor != 0) zc1.setHgq(mutualInductor.toString());
//                else zc1.setHgq(""); //     互感器
//                if (lowBox != 0) zc1.setFzx(lowBox.toString());
//                else zc1.setFzx(""); //     分支箱
//                if (lowCabinet != 0) zc1.setPdg(lowCabinet.toString());
//                else zc1.setPdg(""); //     配电柜
//
//                zcs.add(zc1);
//                ++ios;
//            }else{
//                zc1.setJkgg(lingModleJK); //  架空线路规格
//                if (lingJK != 0) zc1.setJksl(String.valueOf(div(lingJK, 1000, 2)));
//                else zc1.setJksl("");//  架空线路数量
//                zc1.setDlxl(lingModleDL); //  电缆线路规格
//                if (lingDL != 0) zc1.setDlsl(String.valueOf(div(lingDL, 1000, 2)));
//                else zc1.setDlsl(""); //  电缆线路数量
//                zcs.add(zc1);
//            }
//        }
//
//
//
//        return getDataTable(zcs);
//    }


    private static List<String> removeDuplicate(List<String> list) {
        LinkedHashSet<String> set = new LinkedHashSet<String>(list.size());
        set.addAll(list);
        list.clear();
        list.addAll(set);
        return list;
    }


}
